home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Games / Pentominoes 2.0 / Shell ƒ / window layer.c < prev    next >
Encoding:
Text File  |  1995-07-29  |  25.8 KB  |  332 lines  |  [TEXT/MMCC]

  1. ask)
  2.             procID +=movableDBoxProc;
  3.         else
  4.         {
  5.             if (attributes & kHasCloseBoxMask)
  6.                 hasGoAway=TRUE;
  7.             if (attributes & kHasZoomBoxMask)
  8.                 procID +=zoomDocProc;
  9.             if (!(attributes & kHasGrowBoxMask))
  10.                 procID +=noGrowDocProc;
  11.         }
  12.     }
  13.     else
  14.     {
  15.         procID=dBoxProc;
  16.         if (!(attributes & kHasModalBorderMask))
  17.         {
  18.             procID=plainDBox;
  19.             if (attributes & kHasThickDropShadowMask)
  20.                 procID=altDBoxProc;
  21.         }
  22.     }
  23.     
  24.     /* wStorage needs to be allocated _before_ calling MyNewWindow */
  25.     newWindowReference=(WindowRef)wStorage;
  26.     
  27.     if (!gHasColorQD)
  28.         NewWindow(newWindowReference, boundsRect, title, FALSE, procID, (WindowRef)behind,
  29.             hasGoAway, refCon);
  30.     else
  31.         NewCWindow(newWindowReference, boundsRect, title, FALSE, procID, (WindowRef)behind,
  32.             hasGoAway, refCon);
  33.     
  34.     SetWindowMagic(newWindowReference, kMagicNumber);
  35.     
  36.     if (isFloat)
  37.         SetWindowKind(newWindowReference, kApplicationFloaterKind);
  38.     if (isDummy)
  39.         SetWindowKind(newWindowReference, kApplicationDummyKind);
  40.     
  41.     if (visible)
  42.         MyShowWindow(newWindowReference);
  43.     
  44.     return newWindowReference;
  45. }
  46.  
  47. void MyDisposeWindow(WindowRef windowReference)
  48. {
  49.     if (GetWindowVisible(windowReference))
  50.         MyHideWindow(windowReference);
  51.     CloseWindow((WindowRef) windowReference);
  52.     DisposePtr((Ptr) windowReference);
  53. }
  54.  
  55. Boolean MySelectWindow(WindowRef windowToSelect)
  56. /* returns TRUE if window is selected, FALSE if some error or if window is already frontmost */
  57. {
  58.     WindowRef            currentFrontWindow;
  59.     WindowRef            lastFloatingWindow;
  60.     Boolean                isFloatingWindow;
  61.  
  62.     if (GetWindowKind(windowToSelect)==kApplicationFloaterKind)
  63.     {
  64.         isFloatingWindow=TRUE;
  65.         currentFrontWindow=(WindowRef) FrontWindow();
  66.     }
  67.     else
  68.     {
  69.         isFloatingWindow=FALSE;
  70.         currentFrontWindow=GetFrontDocumentWindow();
  71.         lastFloatingWindow=GetLastFloatingWindow();
  72.     }
  73.  
  74.     if (currentFrontWindow!=windowToSelect)
  75.     {
  76.         if (isFloatingWindow)
  77.             BringToFront((WindowRef) windowToSelect);
  78.         else
  79.         {
  80.             if (lastFloatingWindow==0L)
  81.                 SelectWindow((WindowRef) windowToSelect);
  82.             else
  83.             {
  84.                 DeactivateWindow(currentFrontWindow);
  85.                 SendBehind((WindowRef) windowToSelect, (WindowRef) lastFloatingWindow);
  86.                 ActivateWindow(windowToSelect);
  87.             }
  88.         }
  89.         return TRUE;
  90.     }
  91.     
  92.     return FALSE;
  93. }
  94.  
  95. void MyShowWindow(WindowRef windowToShow)
  96. {
  97.     WindowRef            windowBehind;
  98.     WindowRef            frontNonFloatingWindow;
  99.     short                windowClass;
  100.     Boolean                windowIsInFront=FALSE;
  101.     
  102.     if (GetWindowVisible(windowToShow)!=FALSE)
  103.         return;
  104.         
  105.     windowClass=GetWindowKind(windowToShow);
  106.     
  107.     if (windowClass!=kApplicationFloaterKind)
  108.     {
  109.         windowBehind=(WindowRef)GetNextWindow(windowToShow);
  110.         if (windowBehind==GetFrontDocumentWindow())
  111.         {
  112.             if (windowBehind!=0L)
  113.                 DeactivateWindow(windowBehind);
  114.             SetWindowHilite(windowToShow, TRUE);
  115.             windowIsInFront=TRUE;
  116.         }
  117.     }
  118.     else
  119.     {
  120.         ValidateWindowList();
  121.         frontNonFloatingWindow=GetFrontDocumentWindow();
  122.         if ((frontNonFloatingWindow!=0L) &&
  123.             (frontNonFloatingWindow==(WindowRef) FrontWindow()) &&
  124.             (WindowIsModal(frontNonFloatingWindow)))
  125.         {
  126.             SetWindowHilite(windowToShow, FALSE);
  127.         }
  128.         else
  129.         {
  130.             SetWindowHilite(windowToShow, TRUE);
  131.             windowIsInFront=TRUE;
  132.         }
  133.     }
  134.     
  135.     ShowHide((WindowRef) windowToShow, TRUE);
  136.     
  137.     if (windowIsInFront)
  138.     {
  139.         ActivateWindow(windowToShow);
  140.     }
  141.     
  142. #if USE_DRAG
  143.     ResetHiliteRgn(windowToShow);
  144. #endif
  145. }
  146.  
  147. void MyHideWindow(WindowRef windowToHide)
  148. {
  149.     WindowRef            frontFloater;
  150.     WindowRef            frontNonFloater;
  151.     WindowRef            lastFloater;
  152.     WindowRef            windowBehind;
  153.     
  154.     if (GetWindowVisible(windowToHide)==FALSE)
  155.         return;
  156.     
  157.     frontFloater=(WindowRef) FrontWindow();
  158.     if (GetWindowKind(frontFloater)!=kApplicationFloaterKind)
  159.         frontFloater=0L;
  160.     frontNonFloater=FrontNonFloatingWindow();
  161.     
  162.     ShowHide((WindowRef) windowToHide, FALSE);
  163.     
  164.     if (windowToHide==frontFloater)
  165.     {
  166.         windowBehind=GetNextWindow(windowToHide);
  167.         
  168.         if ((windowBehind!=0L) &&
  169.             (GetWindowKind(windowBehind)==kApplicationFloaterKind))
  170.         {
  171.             SetNextWindow(windowToHide, GetNextWindow(windowBehind));
  172.             SetNextWindow(windowBehind, windowToHide);
  173.             SetWindowList(windowBehind);
  174.         }
  175.     }
  176.     else
  177.     {
  178.         if (windowToHide==frontNonFloater)
  179.         {
  180.             windowBehind=GetNextWindow(windowToHide);
  181.             
  182.             if (windowBehind!=0L)
  183.             {
  184.                 SetNextWindow(windowToHide, GetNextWindow(windowBehind));
  185.                 SetNextWindow(windowBehind, windowToHide);
  186.                 lastFloater=LastFloatingWindow();
  187.                 if (lastFloater!=0L)
  188.                 {
  189.                     SetNextWindow(lastFloater, windowBehind);
  190.                 }
  191.                 else
  192.                 {
  193.                     SetWindowList(windowBehind);
  194.                 }
  195.                 
  196.                 ActivateWindow(windowBehind);
  197.             }
  198.         }
  199.     }
  200. }
  201.  
  202. void MyDragWindow(WindowRef windowToDrag, Point startPoint, const Rect *draggingBounds)
  203. {
  204.     Rect            dragRect;
  205.     KeyMap            keyMap;
  206.     GrafPtr            savePort;
  207.     GrafPtr            windowManagerPort;
  208.     RgnHandle        dragRegion;
  209.     RgnHandle        windowContentRegion;
  210.     long            dragResult;
  211.     short            topLimit;
  212.     short            newHorizontalWindowPosition;
  213.     short            newVerticalWindowPosition;
  214.     short            horizontalOffset;
  215.     short            verticalOffset;
  216.     Boolean            commandKeyDown=FALSE;
  217.     
  218.     if (WaitMouseUp())
  219.     {
  220.         topLimit=GetMBarHeight() + 4;
  221.         dragRect=*draggingBounds;
  222.         if (dragRect.top < topLimit)
  223.             dragRect.top=topLimit;
  224.     
  225.         GetPort(&savePort);
  226.         GetWMgrPort(&windowManagerPort);
  227.         SetPort(windowManagerPort);
  228.         SetClip(GetGrayRgn());
  229.         
  230.         GetKeys(keyMap);
  231.         if (keyMap[1] & 0x8000)
  232.             commandKeyDown=TRUE;
  233.     
  234.         if ((commandKeyDown==TRUE) ||
  235.             (GetWindowKind(windowToDrag)!=kApplicationFloaterKind))
  236.         {
  237.             if (commandKeyDown==FALSE)
  238.                 ClipAbove(FrontNonFloatingWindow());
  239.             else
  240.                 ClipAbove(windowToDrag);
  241.         }
  242.             
  243.         dragRegion=NewRgn();
  244.         CopyRgn(GetStructureRegion(windowToDrag), dragRegion);
  245.         
  246.         dragResult=DragGrayRgn(dragRegion, startPoint, &dragRect, &dragRect, noConstraint, 0L);
  247.     
  248.         SetPort(savePort);
  249.  
  250.         if (dragResult!=0)
  251.         {
  252.             horizontalOffset=dragResult & 0xFFFF;
  253.             verticalOffset=dragResult >> 16;
  254.             if (verticalOffset!=-32768)
  255.             {
  256.                 windowContentRegion=GetContentRegion(windowToDrag);
  257.                 newHorizontalWindowPosition=(**windowContentRegion).rgnBBox.left + horizontalOffset;
  258.                 newVerticalWindowPosition=(**windowContentRegion).rgnBBox.top + verticalOffset;
  259.                 MyMoveWindow(windowToDrag, newHorizontalWindowPosition, newVerticalWindowPosition, FALSE);
  260.             }
  261.         }
  262.     
  263.         if (commandKeyDown==FALSE)
  264.             MySelectWindow(windowToDrag);
  265.     
  266.         DisposeRgn(dragRegion);
  267.     }
  268. }
  269.  
  270. void MyMoveWindow(WindowRef theWindow, short h, short v, Boolean selectNow)
  271. {
  272.     Point            theLocalPoint;
  273.     
  274.     MoveWindow(theWindow, h, v, FALSE);
  275.     SetWindowBounds(theWindow,
  276.         (*(((WindowPeek)theWindow)->contRgn))->rgnBBox);
  277.     theLocalPoint.v=GetWindowBounds(theWindow).top;
  278.     theLocalPoint.h=GetWindowBounds(theWindow).left;
  279.     SetWindowTopLeft(theWindow, theLocalPoint);
  280.     if (selectNow)
  281.         MySelectWindow(theWindow);
  282. #if USE_DRAG
  283.     ResetHiliteRgn(theWindow);
  284. #endif
  285. }
  286.  
  287. void MyGrowWindow(WindowRef theWindow, Point theGlobalPoint)
  288. {
  289.     long            windSize;
  290.     GrafPtr            oldPort;
  291.     Rect            sizeRect;
  292.     Point            theLocalPoint;
  293.     
  294.     if (GetGrowSizeDispatch(theWindow, &sizeRect)==kFailure)
  295.         sizeRect=qd.screenBits.bounds;
  296.     
  297.     windSize=GrowWindow(theWindow, theGlobalPoint, &sizeRect);
  298.     if (windSize!=0)
  299.     {
  300.         GetPort(&oldPort);
  301.         SetPort(theWindow);
  302.         SizeWindow(theWindow, LoWord(windSize), HiWord(windSize), TRUE);
  303.         EraseRect(&(theWindow->portRect));
  304.         InvalRect(&(theWindow->portRect));
  305.         SetPort(oldPort);
  306.         
  307.         SetWindowWidth(theWindow, theWindow->portRect.right-theWindow->portRect.left);
  308.         SetWindowHeight(theWindow, theWindow->portRect.bottom-theWindow->portRect.top);
  309.         GrowWindowDispatch(theWindow);
  310.         SetWindowBounds(theWindow,
  311.             (*(((WindowPeek)theWindow)->contRgn))->rgnBBox);
  312.         theLocalPoint.v=GetWindowBounds(theWindow).top;
  313.         theLocalPoint.h=GetWindowBounds(theWindow).left;
  314.         SetWindowTopLeft(theWindow, theLocalPoint);
  315. #if USE_DRAG
  316.         ResetHiliteRgn(theWindow);
  317. #endif
  318.     }
  319. }
  320.  
  321. void MySizeWindow(WindowRef theWindow, short width, short height, Boolean updateNow)
  322. {
  323.     Point            theLocalPoint;
  324.     
  325.     SizeWindow(theWindow, width, height, updateNow);
  326.     SetWindowWidth(theWindow, theWindow->portRect.right-theWindow->portRect.left);
  327.     SetWindowHeight(theWindow, theWindow->portRect.bottom-theWindow->portRect.top);
  328.     GrowWindowDispatch(theWindow);
  329.     SetWindowBounds(theWindow,
  330.         (*(((WindowPeek)theWindow)->contRgn))->rgnBBox);
  331.     theLocalPoint.v=GetWindowBounds(theWindow).top;
  332.     theLocalPoint.h=GetWindowBo